﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Media;
using Styx;
using Styx.Helpers;
using Styx.Common;
using Styx.CommonBot.POI;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;


namespace NuckChorris
{
    public partial class Classname : CombatRoutine
    {

        public bool FlaskBuff()
        {
            if (Me.HasAura("Flask of the Warm Sun")) { return true; }
            if (Me.HasAura("Flask of Winter's Bite")) { return true; }
            if (Me.HasAura("Flask of the Earth")) { return true; }
            if (Me.HasAura("Flask of Spring Blossoms")) { return true; }
            if (Me.HasAura("Flask of Falling Leaves")) { return true; }
            if (Me.HasAura("Flask of the Winds")) { return true; }
            if (Me.HasAura("Flask of Titanic Strenght")) { return true; }
            if (Me.HasAura("Flask of the Draconic Mind")) { return true; }
            if (Me.HasAura("Flask of Flowing Water")) { return true; }
            if (Me.HasAura("Flask of Steelskin")) { return true; }
            if (Me.HasAura("Flask of Endless Rage")) { return true; }
            if (Me.HasAura("Flask of Pure Mojo")) { return true; }
            if (Me.HasAura("Flask of Stoneblood")) { return true; }
            if (Me.HasAura("Flask of the Frost Wyrm")) { return true; }
            if (Me.HasAura("Flask of Toughness")) { return true; }
            if (Me.HasAura("Flask of Binding Light")) { return true; }
            return false;
        }

        #region BagItems
        public bool AlchemistFlask()
        {
            if (NuckChorrisSettings.myPrefs.AlchFlask)
            {

                if (!Me.HasAura("Enhanced Agility") && !FlaskBuff() && !Me.Mounted)
                {
                    foreach (WoWItem item in Me.BagItems)
                    {
                        if (item != null)
                        {
                            if (item.Name == "Alchemist's Flask")
                            {
                                Lua.DoString("RunMacroText(\"/use " + item.Name + "\")");
                                Logging.Write(Colors.LightBlue, "Using Alchemist's Flask");
                                break;
                            }
                        }
                    }
                }
            }
             
            return false;
        }
        public bool HealthStone()
        {
            if (Me.CurrentTarget != null
                && Me.Combat 
                && Me.HealthPercent <= NuckChorrisSettings.myPrefs.healthstone)
            {
                WoWItem hstone = Me.BagItems.FirstOrDefault(h => h.Entry == 5512);
                if (hstone != null && hstone.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    hstone.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Healthstone");
                }
            }
            return false;
        }
        public bool AgiFlask()
        {
            if (Me.CurrentTarget != null
                && Me.Combat && NuckChorrisSettings.myPrefs.AgiFlask
                && !FlaskBuff())
            {
                WoWItem flask = Me.BagItems.FirstOrDefault(h => h.Entry == 76084);
                if (flask != null && flask.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    flask.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Agility Flask");
                }
            }
            return false;
        }
        public bool VirmenPotion()
        {
            if (Me.CurrentTarget != null
                && Me.Combat 
                && NuckChorrisSettings.myPrefs.VirmenPotion)
            {
                WoWItem virmen = Me.BagItems.FirstOrDefault(h => h.Entry == 76089);
                if (virmen != null && virmen.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    virmen.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Virmen Potion");
                }
            }
            return false;
        }
        public bool LifeSpirit()
        {
            if (Me.CurrentTarget != null
                && Me.Combat 
                && Me.HealthPercent <= NuckChorrisSettings.myPrefs.LifeSpirit)
            {
                WoWItem lspirit = Me.BagItems.FirstOrDefault(h => h.Entry == 89640);
                if (lspirit != null && lspirit.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    lspirit.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Life Spirit");
                }
            }
            return false;
        }


        public int DrinkHeal = NuckChorrisSettings.myPrefs.HealthPotion;
        bool DrinkNow = false;
        private static readonly Stopwatch PotionTimer = new Stopwatch();
        public void useItem(WoWItem Item)
        {
            if (!PotionTimer.IsRunning || PotionTimer.ElapsedMilliseconds > (100 + (1000 * 60)))
            {
                Item.Use();
                PotionTimer.Reset();
                PotionTimer.Start();
            }
        }
        public void Drinken()
        {
            if (!Me.Combat)
            {
                DrinkNow = false;
            }
            if (Me.CurrentTarget != null
                && Me.Combat 
                && Me.HealthPercent <= DrinkHeal && !DrinkNow)
            {
                WoWItem UseHealPot = HealDrink();
                if (UseHealPot == null)
                {
                    Logging.Write(Colors.Yellow, "I have no Healing Potions");
                }
                else
                {
                    Logging.Write(Colors.LightBlue, "Use:" + UseHealPot.Name);
                    useItem(UseHealPot);

                }
                DrinkNow = true;
            }
        }
        public WoWItem HealDrink()
        {
            List<WoWItem> Items = ObjectManager.GetObjectsOfType<WoWItem>(false);
            foreach (WoWItem Item in Items)
            {
                switch (Item.Entry)
                {
                    case 76097: return Item; // Master Healing Potion
                    case 80040: return Item; //Endless Master Healing Potion
                    case 63144: return Item; //Baradin's Wardens Healing Potion
                    case 64994: return Item; //Hellscream's Reach Healing Potion
                    case 57193: return Item; //Mighty Rejuvenation Potion
                    case 57191: return Item; //Mythical Healing Potion
                    case 63300: return Item; //Rogue's Draught
                    case 67145: return Item; //Draught of War
                    case 33447: return Item; //Runic Healing Potion
                    case 40077: return Item; //Crazy Alchemist's Potion
                    case 40081: return Item; //Potion of Nightmares
                    case 40087: return Item; //Powerful Rejuvenation Potion
                    case 41166: return Item; //Runic Healing Injector
                    case 43569: return Item; //Endless Healing Potion
                    case 22850: return Item; //Super Rejuvenation Potion
                    case 34440: return Item; //Mad Alchemist's Potion
                    case 39671: return Item; //Resurgent Healing Potion
                    case 31838: return Item; //Major Combat Healing Potion
                    case 31839: return Item; //Major Combat Healing Potion
                    case 31852: return Item; //Major Combat Healing Potion
                    case 31853: return Item; //Major Combat Healing Potion
                    case 32784: return Item; //Red Ogre Brew
                    case 32910: return Item; //Red Ogre Brew Special
                    case 31676: return Item; //Fel Regeneration Potion
                    case 23822: return Item; //Healing Potion Injector
                    case 33092: return Item; //Healing Potion Injector
                    case 22829: return Item; //Super Healing Potion
                    case 32763: return Item; //Rulkster's Secret Sauce
                    case 32904: return Item; //Cenarion Healing Salve
                    case 32905: return Item; //Bottled Nethergon Vapor
                    case 32947: return Item; //Auchenai Healing Potion
                    case 39327: return Item; //Noth's Special Brew
                    case 43531: return Item; //Argent Healing Potion
                    case 18253: return Item; //Major Rejuvenation Potion
                    case 28100: return Item; //Volatile Healing Potion
                    case 33934: return Item; //Crystal Healing Potion
                    case 13446: return Item; //Major Healing Potion
                    case 17384: return Item; //Major Healing Draught
                    case 3928: return Item; //Superior Healing Potion
                    case 9144: return Item; //Wildvine Potion
                    case 12190: return Item; //Dreamless Sleep Potion
                    case 17349: return Item; //Superior Healing Draught
                    case 18839: return Item; //Combat Healing Potion
                    case 1710: return Item; //Greater Healing Potion
                    case 929: return Item; //Healing Potion
                    case 4596: return Item; //Discolored Healing Potion
                    case 858: return Item; //Lesser Healing Potion
                    case 118: return Item; //Minor Healing Potion
                }
            }
            return null;
        }
        #endregion BagItems
    }
}
